package com.nativetalk.common.getui;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.payload.APNPayload;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import org.apache.log4j.Logger;

/**
 * Created by lizhun on 16/3/14.
 */
public class IosCustomerGetui {
    private static Logger logger = Logger.getLogger(IosTeacherGetui.class);

    public final static String appId = "cFkd24m9Lb6WXMct62y1a1";
    public final static String appKey = "uQP7ioK1Fw8dJORaFU2BF6";
    public final static String masterSecret = "IRwqBX8J828i2OFCrcdsK4";
    public final static String url ="http://sdk.open.api.igexin.com/serviceex";
    //使用https的域名
    //static String url = "https://api.getui.com/apiex.htm";
    public static void customer(String title,String body,String devicetoken,String channel,String memb_name
            ,String memb_head,String memb_phone)  {
        TransmissionTemplate template = new TransmissionTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTransmissionType(2);        //应用启动类型，1：强制应用启动 2：等待应用启动
        //APN高级推送
        APNPayload apnpayload = new APNPayload();
        APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
        alertMsg.setBody(body);
        //IOS8.2支持字段
        alertMsg.setTitle(title);

        apnpayload.setAlertMsg(alertMsg);
        apnpayload.setContentAvailable(1);//透传数据
        apnpayload.addCustomMsg("channel",channel);
        apnpayload.addCustomMsg("memb_phone",memb_phone);
        apnpayload.addCustomMsg("memb_head",memb_head);
        apnpayload.addCustomMsg("memb_name",memb_name);
        template.setAPNInfo(apnpayload);

        IGtPush push = new IGtPush(url, appKey, masterSecret);
        SingleMessage message = new SingleMessage();
        message.setData(template);

        IPushResult pushResult = push.pushAPNMessageToSingle(appId,devicetoken,message);
        logger.info(pushResult.getResponse());

    }

}
